﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using FluentValidation;
using CashFlow.Web.Common;
using CashFlow.Web.Areas.ShopManage.Models.User;

namespace CashFlow.Web.Areas.ShopManage.Validator.User
{
    public class ResetShopManagerLevelPercentModelValidator
        : AbstractValidator<ResetShopManagerLevelPercentModel>
    {
        public ResetShopManagerLevelPercentModelValidator()
        {
            CascadeMode = CascadeMode.Stop;
            RuleFor(x => x.UserId).Must(x => CommonValidator.IsUserInShop(x))
                .WithMessage("非法UserId");
            RuleFor(x => x.Percent).Must(x =>
            {
                if (x == 0M)
                {
                    return true;
                }
                else if (RegExpTool.IsShopManagerLevelPercent(x))
                {
                    return true;
                }
                return false;
            }).WithMessage("非法Level");
        }
    }
}